<template>
   <div class="wrapper">
    <swiper :options="swiperOption" v-if="showSwiper">
        <!-- slides -->
        <swiper-slide v-for='item of list' :key='item.id'>
            <img class="wrap-img" :src="item.imgUrl"/>
        </swiper-slide>
        <!-- Optional controls -->
        <div class="swiper-pagination"  slot="pagination"></div>
    </swiper>
  </div>
</template>

<script>
export default {
  name: 'HomeSwiper',
  props: {
    list: Array
  }, // 父组件传递过来的list
  data () {
    return {
      swiperOption: {
        pagination: '.swiper-pagination',
        loop: true,
        autoplay: 2800
      }
    }
  }, // 这个计算属性是计算banner图的个数。用于处理默认显示最后一张图的问题
  computed: {
    showSwiper () {
      return this.list.length
    }
  }
}
</script>

<style lang="stylus" scoped>
.wrapper>>> .swiper-pagination-bullet-active
  background #555!important

.wrapper
  width 100%
  height:0
  padding-bottom 3.6rem
  .wrap-img
    width 100%
</style>
